using System;
using System.Collections.Generic;
using OracleInternal.Common;

namespace OracleInternal.TTC.Accessors
{
	internal class TTCPLSQLBooleanAccessor : Accessor
	{
		internal const int MAX_BOOLEAN_LENGTH = 2;

		internal static byte[] TRUE_VAL_BYTES = new byte[2]
		{
			1,
			1
		};

		internal static byte[] FALSE_VAL_BYTES = new byte[1];

		internal TTCPLSQLBooleanAccessor(ColumnDescribeInfo colMetaData, MarshallingEngine marshallingEngine, bool bForBind)
			: base(colMetaData, marshallingEngine, bForBind)
		{
			if (!bForBind)
			{
				InitForDataAccess(colMetaData.m_maxLength);
			}
		}

		internal object GetBooleanValue(int currentRow)
		{
			object result = null;
			if (m_totalLengthOfData[currentRow] > 0)
			{
				List<ArraySegment<byte>> list = m_RowDataSegments[currentRow];
				if (list != null)
				{
					byte valueAt = Accessor.GetValueAt(list, 0);
					if (valueAt == 0)
					{
						result = Convert.ToBoolean(valueAt);
					}
					else if (1 == valueAt)
					{
						result = Convert.ToBoolean(Accessor.GetValueAt(list, 1));
					}
					else
					{
						bool flag = false;
						if ((valueAt & 0x80) > 0)
						{
							valueAt = (byte)(valueAt & 0x7Fu);
							flag = true;
						}
						int num = Accessor.GetValueAt(list, 1);
						if (flag)
						{
							num = -num;
						}
						if (-1 == num)
						{
							result = null;
						}
					}
				}
			}
			return result;
		}
	}
}
